<?php 
/*


*/

if ($id == "default") { 
// if displaying the course progress entirely (NOT in a modal window)

	do { 
	$query_assignments = sprintf("SELECT * FROM assignments WHERE cid='%s' AND mid='%s' ORDER BY assign_num ASC", $cid, $row_modules['mid']);
	$assignments = mysql_query($query_assignments, $connection) or die(mysql_error());
	$row_assignments = mysql_fetch_assoc($assignments);
	
	$query_themes = sprintf("SELECT * FROM themes WHERE cid='%s' AND mid='%s' ORDER BY theme_num ASC", $cid, $row_modules['mid']);
	$themes = mysql_query($query_themes, $connection) or die(mysql_error());
	$row_themes = mysql_fetch_assoc($themes);
	$totalRows_themes = mysql_num_rows($themes);
	//echo $query_themes;
	//echo $totalRows_themes;
	?>
<h2><a name="<?php echo $row_modules['mid']; ?>"></a>Module <?php echo $row_modules['mid']; ?>:
	<?php if ($row_modules['module_title'] != "") echo $row_modules['module_title']; else { ?><span class="icon"><img src="images/exclamation.png" border="0" align="absmiddle" /></span>No Title Entered<?php } ?></h2>
    <?php if ($modal_window != "true") { ?>
    <div class="stacked">
    <span class="icon"><img src="images/monitor.png" border="0" align="absmiddle" /></span><a id="modal_window_link" href="index.php?section=view_course&amp;action=default&amp;go=module&amp;dbTable=modules&amp;cid=<?php echo $cid; ?>&amp;mid=<?php echo $row_modules['mid']; ?>&amp;id=<?php echo $row_modules['id']; ?>&amp;modal_window=true">View Module <?php echo $row_modules['mid']; ?></a><br />
	</div>
	<?php } ?>
<?php 
	include (MODULES.'display_module_overview.sec.php');
	include (MODULES.'display_module_lo.sec.php');
	include (MODULES.'display_module_readings.sec.php');
	include (MODULES.'display_module_themes.sec.php');
	include (MODULES.'display_module_assignments.sec.php');
?>

<?php } while ($row_modules = mysql_fetch_assoc($modules)); ?>
<?php } // end if ($id == "default") ?>

<?php if ($id != "default") { 
// for displaying an idividual module (or a part thereof) in a modal window

?>
<a name="titles"></a><h1 class="module-title">Module <?php echo $row_modules['mid'].": ".$row_modules['module_title']; ?></h1>
<div id="content-inner">
<div id="preview">
<?php if ($go == "module") { ?>
<h1>Module Overview</h1>
<?php if ($row_modules['module_overview'] != "") echo "<p>".$row_modules['module_overview']."</p>"; else { ?><span class="icon"><img src="images/exclamation.png" border="0" align="absmiddle" /></span>No Overview Entered<?php } ?>
<h1>Module Learning Outcomes</h1>
<p>Upon successful completion of this module, you will be able to:</p>
<ul>
	<li>Outcome</li>
    <li>Outcome</li>
    <li>Outcome</li>
</ul>
<h1>Readings</h1>
<?php 
	
	if ($totalRows_readings > 0) {
	do {  ?>
    <blockquote>
    <p class="cite"><?php echo get_material_info($row_readings['reading_material'],"name",1); ?></p>
    <?php if ($row_readings['reading_assignment'] != "") echo "<p class='cite-indent'>".$row_readings['reading_assignment']; if ($row_readings['reading_notes'] != "") echo "<br>Note: <em>".$row_readings['reading_notes']."</em>"; ?>
    </blockquote>
	<?php } while ($row_readings = mysql_fetch_assoc($readings)); 
    } else echo "<p>No readings have been entered for this module.</p>"; 
	
	// ------------------- Themes -------------------		
			do { $d[] = $row_themes['theme_num']; } while ($row_themes = mysql_fetch_assoc($themes));
			sort($d);
			foreach (array_unique($d) as $value1) {
				$query_theme_loop = sprintf("SELECT * FROM themes WHERE cid='%s' AND mid='%s' AND theme_num='%s' ORDER BY vid DESC LIMIT 1", $cid, $row_modules['mid'], $value1);
				$theme_loop = mysql_query($query_theme_loop, $connection) or die(mysql_error());
				$row_theme_loop = mysql_fetch_assoc($theme_loop);
				$totalRows_theme_loop = mysql_num_rows($theme_loop);
				
				$query_theme_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='themes' AND rid='%s'", $cid, $row_theme_loop['id']);
				$theme_comments = mysql_query($query_theme_comments, $connection) or die(mysql_error());
				$row_theme_comments = mysql_fetch_assoc($theme_comments);
				$totalRows_theme_comments = mysql_num_rows($theme_comments);
				
				if ($totalRows_theme_loop > 0) { ?>
    <h1><?php echo "Theme ".$row_theme_loop['theme_num'].": ".$row_theme_loop['theme_title']; ?></h1>
    <div class="theme-content">
    <?php if ($row_theme_loop['theme_text'] != "") echo $row_theme_loop['theme_text']; else echo "<p>No content has been entered for this theme.</p>"; ?>
    </div>
	<?php
		}
	} //else echo "<p>No themes have been entered for this module.</p>"; 
	
	// ------------------- Assignments -------------------		
			do { $e[] = $row_assignments['assign_num']; } while ($row_assignments = mysql_fetch_assoc($assignments));
			sort($e);
			foreach (array_unique($e) as $value1) {
				$query_assignment_loop = sprintf("SELECT * FROM assignments WHERE cid='%s' AND mid='%s' AND assign_num='%s' ORDER BY vid DESC LIMIT 1", $cid, $row_modules['mid'], $value1);
				$assignment_loop = mysql_query($query_assignment_loop, $connection) or die(mysql_error());
				$row_assignment_loop = mysql_fetch_assoc($assignment_loop);
				$totalRows_assignment_loop = mysql_num_rows($assignment_loop);
				
				$query_assignment_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='assignments' AND rid='%s'", $cid, $row_assignment_loop['id']);
				$assignment_comments = mysql_query($query_assignment_comments, $connection) or die(mysql_error());
				$row_assignment_comments = mysql_fetch_assoc($assignment_comments);
				$totalRows_assignment_comments = mysql_num_rows($assignment_comments);
				
				if ($totalRows_assignment_loop > 0) { ?>
    <h1><?php echo "Assignment ".$row_assignment_loop['mid'].".".$row_assignment_loop['assign_num'].": ".$row_assignment_loop['assign_title']; ?></h1>
    <div class="theme-content">
    <?php if (($row_assignment_loop['assign_overview'] != "") && ($row_assignment_loop['assign_procedure'] != "")) { ?>
	<?php echo $row_assignment_loop['assign_overview']; ?>
	<h2>Procedure</h2>
	<?php echo $row_assignment_loop['assign_procedure']; ?>
	<h2>Evaluation</h2>
	<p>Your assignment is worth <?php echo $row_assignment_loop['assign_points']; ?> points.</p>
	<?php if ($row_assignment_loop['assign_rubrics'] != "") { ?>
	<p>Your assignment will be evaluated based upon the following rubrics:</p>
	<ul>
	<?php 
	$a = explode(",",$row_assignment_loop['assign_rubrics']);
	foreach ($a as $value) {
		$query_rubrics = "SELECT * FROM rubrics WHERE id='$value'";
		$rubrics = mysql_query($query_rubrics, $connection) or die(mysql_error());
		$row_rubrics = mysql_fetch_assoc($rubrics);
		
		echo "<li>"; 
		if ($row_rubrics['rubric_path'] != "") echo "<a href='".$row_rubrics['rubric_path']."' target='_blank'>".$row_rubrics['rubric_name']."</a>"; else echo $row_rubrics['rubric_name'];
		echo "</li>";
		}
?>
	</ul>
	<?php } ?>
    <h2>Workplace Compentencies</h2>
    <p>Your assignment will be evaluated based upon the following criteria:</p>
    <ul>
    <?php 
    $a = explode(",",$row_assignment_loop['assign_wp']);
    foreach ($a as $value) {
        $query_wp = "SELECT * FROM workplace_comps WHERE id='$value'";
        $wp = mysql_query($query_wp, $connection) or die(mysql_error());
        $row_wp = mysql_fetch_assoc($wp);
        
        echo "<li><strong>".$row_wp['wp_name']."</strong> &mdash; ".$row_wp['wp_info']."</li>";
    }
    ?>
    </ul>
	<?php } else echo "<p>No content has been entered for this assignment.</p>"; ?>
    </div>
	<?php
		}
	} 
}

if ($go == "theme") { 
// display an individual theme ONLY
?>
<div class="info">Version <?php echo $row_themes['vid']; ?></div>
    <h1><?php echo "Theme ".$row_themes['theme_num'].": ".$row_themes['theme_title'];  ?> </h1>
    <?php echo $row_themes['theme_text']; ?>
<?php } //end if ($go == "theme") 
if ($go == "assignment") { 
// display an individual assignment ONLY 
?>
<div class="info">Version <?php echo $row_assignments['vid']; ?></div>
    <h1><?php echo "Assignment ".$mid.".".$row_assignments['assign_num'].": ".$row_assignments['assign_title']; ?></h1>
    <?php echo $row_assignments['assign_overview']; ?>
    <h2>Procedure</h2>
    <?php echo $row_assignments['assign_procedure']; ?>
    <h2>Evaluation</h2>
    <p>Your assignment is worth <?php echo $row_assignments['assign_points']; ?> points.</p>
    <?php if ($row_assignments['assign_rubrics'] != "") { ?>
    <p>Your assignment will be evaluated based upon the following rubrics:</p>
    <ul>
    <?php 
    $a = explode(",",$row_assignments['assign_rubrics']);
    foreach ($a as $value) {
        $query_rubrics = "SELECT * FROM rubrics WHERE id='$value'";
        $rubrics = mysql_query($query_rubrics, $connection) or die(mysql_error());
        $row_rubrics = mysql_fetch_assoc($rubrics);
        
        echo "<li>"; 
        if ($row_rubrics['rubric_path'] != "") echo "<a href='".$row_rubrics['rubric_path']."' target='_blank'>".$row_rubrics['rubric_name']."</a>"; else echo $row_rubrics['rubric_name'];
        echo "</li>";
    }
    ?>
    </ul>
    <?php } ?>
    <h2>Workplace Compentencies</h2>
    <p>Your assignment will be evaluated based upon the following criteria:</p>
    <ul>
    <?php 
    $a = explode(",",$row_assignments['assign_wp']);
    foreach ($a as $value) {
        $query_wp = "SELECT * FROM workplace_comps WHERE id='$value'";
        $wp = mysql_query($query_wp, $connection) or die(mysql_error());
        $row_wp = mysql_fetch_assoc($wp);
        
        echo "<li><strong>".$row_wp['wp_name']."</strong> &mdash; ".$row_wp['wp_info']."</li>";
    }
    ?>
    </ul>
<?php } // if ($go == "assignment") ?>
</div>
</div> 
<?php } // end if ($id != "default") ?>